unit GMedRusis;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, GForm, cxGraphics, cxPropertiesStore, dxBarExtItems, dxBar,
  cxClasses, ActnList, dxStatusBar, cxControls, cxPC, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridCustomView,
  cxGrid, cxNavigator, cxDBNavigator, cxContainer, cxGroupBox, impexp,
  cxLookAndFeelPainters;

type
  TfMedRusis = class(TGamaForm)
    tsSarasas: TcxTabSheet;
    dbgSarasas: TcxGrid;
    dbgSarasasDBTableView: TcxGridDBTableView;
    dbgSarasasLevel1: TcxGridLevel;
    cxGroupBox1: TcxGroupBox;
    dbnNav: TcxDBNavigator;
    dbgSarasasDBTableViewrusis: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure GmiImportasClick(Sender: TObject);
  private
    { Private declarations }
    m_arImportas: boolean;

    procedure LentelesOn;
    procedure LentelesOff;
    //
    procedure MainBeforeInserOrEdit(DataSet: TDataSet);
    procedure MainBeforePost(DataSet: TDataSet);
    procedure MainAfterPostOrDelete(DataSet: TDataSet);
    procedure MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
    procedure MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
    procedure MainNewRecord(DataSet: TDataSet);
  public
    { Public declarations }
    procedure RefreshTables; override;
  end;

var
  fMedRusis: TfMedRusis;

implementation

{$R *.dfm}

uses
  bendri, med_dm, Tools;

procedure TfMedRusis.LentelesOn;
begin
  with dmMed do begin
    tbMedRusis.BeforeInsert  := self.MainBeforeInserOrEdit;
    tbMedRusis.BeforeEdit    := self.MainBeforeInserOrEdit;
    tbMedRusis.BeforePost    := self.MainBeforePost;
    tbMedRusis.AfterPost     := self.MainAfterPostOrDelete;
    tbMedRusis.AfterDelete   := self.MainAfterPostOrDelete;
    tbMedRusis.AfterCancel   := self.MainAfterPostOrDeleteOrCancel;
    //tbMedRastKub.OnPostError   := self.MainPostError;
    tbMedRusis.OnNewRecord   := self.MainNewRecord;
  end;
end;

procedure TfMedRusis.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  LentelesOff;
end;

procedure TfMedRusis.FormShow(Sender: TObject);
begin
  inherited;
  LentelesOn;
end;

procedure TfMedRusis.GmiImportasClick(Sender: TObject);
begin
  try
    LentelesOff;
    m_arImportas := true;
    fImpExp.DataSet := dmMed.tbMedRusis;
    dmMed.tbMedRusis.DisableControls;
    //fImpExp.BeforeStart := ImportBeforeStart;
    //fImpExp.AfterEnd := ImportAfterEnd;
    //dmVagonai.tbVStotys.OnNewRecord := self.StotysNewRecord;
    //fImpExp.BeforeInsert := ImportBeforeInsert;
    fImpExp.ImEx := importas;
    fImpExp.IniFileName := 'ismatavimai.ini';
    if fImpExp.ShowModal(DokTipas) <> mrYes then Exit;
  finally
    m_arImportas := false;
    dmBendras.ApplyUpdatesAfterPostOrDelete( dmMed.tbMedRusis );
    dmMed.tbMedRusis.Refresh;
    dmMed.tbMedRusis.EnableControls;
    bRefreshTables := true;
    //dmVagonai.tbVVagonaiS.Refresh;
    LentelesOn;
  end;
end;

procedure TfMedRusis.LentelesOff;
begin
  with dmMed do begin
    tbMedRusis.BeforeInsert  := nil;
    tbMedRusis.BeforeEdit    := nil;
    tbMedRusis.BeforePost    := nil;
    tbMedRusis.AfterPost     := nil;
    tbMedRusis.AfterDelete   := nil;
    tbMedRusis.AfterCancel   := nil;
    //tbMedRastKub.OnPostError   := nil;
    tbMedRusis.OnNewRecord   := nil;
  end;
end;

procedure TfMedRusis.MainBeforePost(DataSet: TDataSet);
begin
  //MessageText := '';
  //dmBendras.RandomIDBeforePost(DataSet);
end;

procedure TfMedRusis.MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
begin
  //dmBendras.RandomIDPostError(DataSet, E, Action);
end;

procedure TfMedRusis.MainNewRecord(DataSet: TDataSet);
begin
  //
end;

procedure TfMedRusis.MainAfterPostOrDelete(DataSet: TDataSet);
begin
  dmBendras.ApplyUpdatesAfterPostOrDelete(DataSet);
  MainAfterPostOrDeleteOrCancel(DataSet);
  bRefreshTables := true;
end;

procedure TfMedRusis.MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, false );
end;

procedure TfMedRusis.MainBeforeInserOrEdit(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, true);
end;

procedure TfMedRusis.RefreshTables;
begin
  if bRefreshTables then begin
    bRefreshTables := false;
    //dmAlga.tbIssilavLookup.Refresh;
  end
end;

end.
